#include <bits/stdc++.h>

using namespace std;
#define fo(i, a, b) for (int i = a; i <= b; i ++) //for 循环
#define cin(n) scanf("%d", &n) // 输入n
#define ve(n, a) vector<int> a(n)
#define endl '\n'
#define fi first
#define se second
const int N = 10;
int a[N][N];
int c, d, h, ans, nx, ny;
bool vis[N][N];
int n, m;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
bool dfs(int x, int y, int sum) {
	if (x == nx && ny == y && sum >= d) return true;
	for (int i = 0; i < 4; i ++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx <= n && ny <= m && nx >= 1 && ny >= 1  && a[nx][ny] != 11 && !vis[nx][ny]) {
			vis[nx][ny] = true;
			if(dfs(nx, ny, sum + a[nx][ny])) return true;
			vis[nx][ny] = false;
		}
	}
	return false;
}
void solve() {
	while (cin >> n >> m) {
		int tx, ty;
		memset(a, 0, sizeof a);
		memset(vis, 0, sizeof vis);
		int sum = 0;
		fo (i, 1, n) {
			fo (j, 1, m) {
				char c;
				cin >> c;
				if (c == 'S') tx = i, ty = j;
				if (c == 'X') a[i][j] = 11;
				if (c == 'B') nx = i, ny = j;
				if (c >= '0' && c <= '9') a[i][j] = c - '0', sum += a[i][j];
			}
		}
		cin >> c >> d;
		//cout << sum << endl;
		vis[tx][ty] = 1;
		if (sum + c >= d && dfs(tx, ty, c)) puts("YES");
		else puts("NO");
	}
}
signed main() {
	int t = 1;
//	scanf("%d", &t);
	while (t --) {
		solve();
	}
	return 0;
}
